package com.nmgydy.task;

import com.alibaba.fastjson.JSON;
import com.nmgydy.beans.ResultBean;
import com.nmgydy.model.Court;
import com.nmgydy.model.EventItem;
import com.nmgydy.model.MoveHistory;
import com.nmgydy.service.EventItemService;
import com.nmgydy.util.ConfigUtil;
import com.nmgydy.util.Functions;
import com.nmgydy.util.HibernateDao;
import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.jdbc.ReturningWork;
import org.hibernate.jdbc.Work;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;


@Component
public class EventTask {

	@Resource
	private EventItemService eventItemService;

	@Resource
	private HibernateDao hibernateDao;

	private static Boolean taskSwitch = ConfigUtil.getBooleanValue("task.switch");

	@Scheduled(cron="0 0/10 * * * ?")
	public void doCheck(){
		if(taskSwitch){
			System.out.println("-- 自动计时 --");
			eventItemService.overToday();
		}
	}



	public static void main(String[] args) {
		EventTask eventTask = new EventTask();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			Date startDay = sdf.parse("2023-10-07 21:17:00");
			//System.out.println(eventTask.dayOffset(startDay));
		} catch (ParseException e) {
			e.printStackTrace();
			return;
		}
	}

}
